package com.yanqu.road.server.gameplayer.module.cricket.model;

import com.yanqu.road.entity.enums.eSkillType;
import com.yanqu.road.pb.cricket.CricketProto;

public class SkillData {

    public static SkillData getInstance(SkillEffect skillEffect) {
        return new SkillData(skillEffect);
    }

    private SkillData(SkillEffect skillEffect) {
        this.skillId = skillEffect.getSkillId();
        this.skillEffect = skillEffect;
        initCoolingDown();
        initEffectRound();
    }

    private int skillId;
    private SkillEffect skillEffect;


    private long fromUserId;
    /**
     * 叠加层数
     */
    private int overlay;
    /**
     * 技能冷却回合
     */
    private int coolingDown = 0;
    /**
     * 持续回合
     */
    private int effectRound = 0;
    /**
     * 生效次数
     */
    private int effectAmount = 0;

    /**
     * 本轮是否释放
     */
    private boolean isRelease = false;


    public int getSkillId() {
        return skillId;
    }

    public void setSkillId(int skillId) {
        this.skillId = skillId;
    }

    public SkillEffect getSkillEffect() {
        return skillEffect;
    }

    public void setSkillEffect(SkillEffect skillEffect) {
        this.skillEffect = skillEffect;
    }

    public long getFromUserId() {
        return fromUserId;
    }

    public void setFromUserId(long fromUserId) {
        this.fromUserId = fromUserId;
    }

    public int getOverlay() {
        return overlay;
    }

    public void setOverlay(int overlay) {
        this.overlay = overlay;
    }

    public CricketProto.CricketBattleSkillDataTemp.Builder toBattleSkillDataBuilder() {
        CricketProto.CricketBattleSkillDataTemp.Builder builder = CricketProto.CricketBattleSkillDataTemp.newBuilder();
        builder.setSkillId(this.getSkillId());
        builder.setFromUserId(this.getFromUserId());
        builder.setOverlay(this.getOverlay());
        builder.setCoolingDown(this.getCoolingDown());
        builder.setEffectRound(this.getEffectRound());
        builder.setFromUserId(this.getFromUserId());
        return builder;
    }

    public int getCoolingDown() {
        return coolingDown;
    }

    public void setCoolingDown(int coolingDown) {
        this.coolingDown = coolingDown;
    }

    public void initCoolingDown() {
        int skillType = this.getSkillEffect().getSkillType();
        if (skillType == eSkillType.CricketBattleSkill160.getValue() ||
                skillType == eSkillType.CricketBattleSkill161.getValue() ||
                skillType == eSkillType.CricketBattleSkill162.getValue()) {
            this.coolingDown = skillEffect.getP3();
        }
    }

    public int getEffectRound() {
        return effectRound;
    }

    public void setEffectRound(int effectRound) {
        this.effectRound = effectRound;
    }

    public void initEffectRound() {
        int skillType = this.getSkillEffect().getSkillType();
        if (skillType == eSkillType.CricketBattleSkill163.getValue()) {
            this.effectRound = skillEffect.getP1();
        }
    }

    public int getEffectAmount() {
        return effectAmount;
    }

    public void effectAmountInc() {
        this.effectAmount++;
        isRelease = true;
    }

    public boolean isRelease() {
        return isRelease;
    }

    public void setRelease(boolean release) {
        isRelease = release;
    }
}
